package com.example.shixi.controller;

import com.example.shixi.domain.BlogFriendAddress;
import com.example.shixi.service.FriendService;
import com.example.shixi.service.LogService;
import com.example.shixi.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private LogService logService;
    @Autowired
    private FriendService friendService;
    @GetMapping("/query/{pageNum}/{pageSize}")
    public JSONResult query(BlogFriendAddress ba, @PathVariable Integer pageNum, @PathVariable Integer pageSize,String updateUserName){
        logService.add(updateUserName, "查看友情链接列表");
        return friendService.query(ba,pageNum,pageSize);
    }
    @PostMapping("/add")
    public JSONResult add(@RequestBody BlogFriendAddress ba,String updateUserName){
        logService.add(updateUserName, "增加友情链接");
        return friendService.add(ba);
    }
    @ DeleteMapping("/del/{id}")
    public JSONResult del(@PathVariable Long id,String updateUserName){
        logService.add(updateUserName, "删除友情链接");
        return friendService.del(id);
    }
    @PutMapping("/update")
    public JSONResult update(@RequestBody BlogFriendAddress ba,String updateUserName){
        logService.add(updateUserName, "更新友情链接");
        return friendService.update(ba);
    }
}
